
package com.zsrt.day20170418.ch02;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;


import org.junit.Test;

public class DateTest {

	Date date = new Date();
	
	/**
	 * 从1970年1月1日开始的毫秒数
	 * @throws Exception
	 */
	@Test
	public void test01() throws Exception {
		
		long time = date.getTime();
		System.out.println(time);
		
	}
	
	/**
	 * 天数
	 * @throws Exception
	 */
	@SuppressWarnings("deprecation")
	@Test
	public void test02() throws Exception {
		int day = date.getDate();
		System.out.println(day);
	}
	
	
	/**
	 * 从1900年到现在的年数
	 * @throws Exception
	 */
	@SuppressWarnings("deprecation")
	@Test
	public void test03() throws Exception {
		int day = date.getYear();
		System.out.println(day);
	}
	
	
	@Test
	public void test04() throws Exception {
		
		Calendar calendar= Calendar.getInstance();
		System.out.println(calendar);
	}
	
	@Test
	public void test05() throws Exception {
		
		String pattern = "YYYY-MM-dd";
		DateFormat dateFormat = new SimpleDateFormat(pattern);
		
		Date date = new Date();
		System.out.println(date);
	
		//转换成"YYYY-MM-dd" 格式
		System.out.println(dateFormat.format(date));
	}
}
